[consoleui] Make it easier to extend ConsolePrompt
#1068
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is meant as somewhat of a first step towards fixing #1051 .
When trying out different scenarios I was running into the issue that
ConsolePrompt
has all this useful code but it's somewhat hard to extend it because all its innards are private.So the first commit is simply making those private fields and methods
protected
.The second commit splits up the
prompt()
method. It's quite a big method that has both a loop and a whole bunch of of code to handle the different kinds of prompt elements that are supported. The fact that all that code is inside the loop makes it basically impossible to add any new element types or to try to handle any of them differently without basically copying and pasting the entire code to a new class.So the second commit splits the
prompt()
method in two: the publicprompt()
still has the loop but the loop is now simplified to mostly calling a new protected method calledpromptElement()
. This gives a subclass the possibility to override thepromptElement()
method to, for example, add support for a new custom element type.They are not big changes but they make experimenting with the consoleui a whole lot easier and more powerful.
Wdyt @mattirn ?